package com.summer.web.v1.controller;

import com.summer.common.lib.core.interfaces.RestController;
import com.summer.web.v1.base.props.AppProps;
import com.summer.web.v1.service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Path;
import java.util.logging.Logger;

@Path("/register")
public class RegisterRestController implements RestController {

    Logger logger = Logger.getLogger(RegisterRestController.class.getName());

    @Resource(name = "bean/UserService")
    private UserService userService;
    @Resource(name = "bean/AppProps")
    private AppProps appProps;

    @Path("/reg")
    @Override
    public Object execute(HttpServletRequest req) throws Throwable {

        String applicationName = appProps.getApplicationName();

        logger.info("RegisterRestController.register.reg execute, hash address = " + this.getClass().hashCode());

        String name = req.getParameter("userName");

        String password = req.getParameter("pwd");

        String email = req.getParameter("email");

        String phoneNumber = req.getParameter("phone");

        return userService.insertUser(applicationName + name, password, email, phoneNumber);
    }

}
